home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoPageMark.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.3 KB  |  277 lines

  1. /*
  2.  *   $RCSfile: undoPageMark.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "page.h"
  49. #include "lock.h"
  50. #include "object.h"
  51. #include "msgdefs.h"
  52. #include "thread.h"
  53. #include "latch.h"
  54. #include "semaphore.h"
  55. #include "link.h"
  56. #include "lsn.h"
  57. #include "bf.h"
  58. #include "log.h"
  59. #include "volume.h"
  60. #include "logrecs.h"
  61. #include "openlog.h"
  62. #include "trans.h"
  63. #include "bitmap.h"
  64. #include "undo.h"
  65. #include "io_extfuncs.h"
  66. #include "bf_extfuncs.h"
  67. #include "bm_extfuncs.h"
  68. #include "log_extfuncs.h"
  69. #include "undo_extfuncs.h"
  70. #include "logaction.h"
  71. #include "util_funcs.h"
  72. #include "thread_globals.h"
  73.  
  74.  
  75.  void
  76. undoPageMark (
  77.  
  78.     LOGRECORDHDR        *recordHeader 
  79. )
  80. {
  81.  
  82.     register VOLREC        *volRec;
  83.     register PID        *pid;
  84.     register GROUPLINK    *groupLink;
  85.     register FOUR        pageOffset;
  86.     LOGRECORDINFO        recordInfo;
  87.     FORCEMARK            forceMark;
  88.     LSN                    lsn;
  89.     LRC                    *lrc;
  90.     PID                    bitmapPid;
  91.  
  92.  
  93.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
  94.  
  95.     /*
  96.      *    get a pointer to the name in the record
  97.      */
  98.     pid = (PID *) GET_LOG_IMAGE(recordHeader, 0);
  99.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  100.  
  101.     if ((volRec = io_FindVolRec(pid->volid)) == NULL)    {
  102.  
  103.         SM_ERROR(TYPE_FATAL, Active->errno);
  104.     }
  105.  
  106. /*
  107.  *  If debugging is turned on, we should validate that the
  108.  *  actionPid matches the bitmap page holding the page in
  109.  *  image 0.
  110.  */
  111. #ifdef DEBUG
  112.  
  113.     /*
  114.      *    initialize the pid with the volume
  115.      */
  116.     bitmapPid.volid = volRec->header->volid;
  117.  
  118.     /*
  119.      *    calculate the offset to the correct page
  120.      */
  121.     pageOffset = BIT_TO_PAGE(pid->page);
  122.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pageOffset:%d", pageOffset));
  123.  
  124.     /*
  125.      *    Check the type to see if we should set any of the bitmaps
  126.      */
  127.     switch (recordHeader->action)    {
  128.  
  129.         case LOG_ACTION_MARK_SLOTTED_PAGE:
  130.         case LOG_ACTION_UNMARK_SLOTTED_PAGE:
  131.  
  132.             /*
  133.              *    get the pid of the correct slotted bitmap page
  134.              */
  135.             bitmapPid.page = volRec->header->slotBitmapAddr + pageOffset;
  136.             TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("slotted bitmap page:%d", bitmapPid.page));
  137.             break;
  138.  
  139.         case LOG_ACTION_MARK_FILE_PAGE:
  140.         case LOG_ACTION_UNMARK_FILE_PAGE:
  141.  
  142.             /*
  143.              *    get the pid of the correct file bitmap page
  144.              */
  145.             bitmapPid.page = volRec->header->fileBitmapAddr + pageOffset;
  146.             TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("fileheader bitmap page:%d", bitmapPid.page));
  147.             break;
  148.  
  149.         default:
  150.  
  151.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  152.             break;
  153.     }
  154.  
  155.     SM_ASSERT(LEVEL_1, PIDEQ(recordHeader->actionPid, bitmapPid));
  156.  
  157. #else
  158.  
  159.     /*
  160.      *  Debugging is off, so assign the bitmap page to be the actionPid
  161.      */
  162.     bitmapPid = recordHeader->actionPid;
  163.  
  164. #endif DEBUG
  165.  
  166.     /*
  167.      *    read in the page
  168.      */
  169.     if ((groupLink = bf_ReadPage(volRec->bufGroup, &bitmapPid,
  170.                                  BITMAP_PAGE2SIZE, BF_SEM)) == NULL)    {
  171.  
  172.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  173.     }
  174.  
  175.     /*
  176.      *  get the lrc on the bitmap page and increment it
  177.      */
  178.     lrc = &(((BITMAPPAGE *) groupLink->bufFrame)->lrc);
  179.     INCREMENT_LRC(lrc);
  180.  
  181.     /*
  182.      *    set the type of the new log record
  183.      */
  184.     switch (recordHeader->action)    {
  185.  
  186.         case LOG_ACTION_MARK_SLOTTED_PAGE:
  187.  
  188.             recordInfo.action = LOG_ACTION_UNMARK_SLOTTED_PAGE;
  189.             break;
  190.  
  191.         case LOG_ACTION_UNMARK_SLOTTED_PAGE:
  192.  
  193.             recordInfo.action = LOG_ACTION_MARK_SLOTTED_PAGE;
  194.             break;
  195.  
  196.         case LOG_ACTION_UNMARK_FILE_PAGE:
  197.  
  198.             recordInfo.action = LOG_ACTION_MARK_FILE_PAGE;
  199.             break;
  200.  
  201.         case LOG_ACTION_MARK_FILE_PAGE:
  202.  
  203.             recordInfo.action = LOG_ACTION_UNMARK_FILE_PAGE;
  204.             break;
  205.  
  206.         default:
  207.  
  208.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  209.             break;
  210.     }
  211.  
  212.     /*
  213.      *    initialize the log information
  214.      */
  215.     recordInfo.type            = LOG_REC_TYPE_COMPENSATION;
  216.     recordInfo.flags        = NOFLAGS;
  217.     recordInfo.imageCount    = 1;
  218.     recordInfo.actionPid    = &bitmapPid;
  219.     recordInfo.actionLRC    = lrc;
  220.     recordInfo.imageSize[0] = sizeof(PID);
  221.     recordInfo.imageData[0] = (VOID *) pid;
  222.     recordInfo.nextUndoLSN    = recordHeader->previousLSN;
  223.  
  224.     /*
  225.      *    write the record to the log
  226.      */
  227.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec,
  228.                                     &recordInfo, &lsn, NOFLAGS)) < 0)    {
  229.         
  230.         SM_ERROR(TYPE_FATAL, Active->errno);
  231.     }
  232.  
  233.     /*
  234.      *    check to see if we are to set or unset the bit
  235.      */
  236.     switch (recordInfo.action)    {
  237.  
  238.         case LOG_ACTION_UNMARK_FILE_PAGE:
  239.         case LOG_ACTION_UNMARK_SLOTTED_PAGE:
  240.  
  241.             /*
  242.              *    clear the bit
  243.              */
  244.             bm_ClearBit((UFOUR *) groupLink->bufFrame, BIT_IN_PAGE(pid->page));
  245.             break;
  246.     
  247.         case LOG_ACTION_MARK_FILE_PAGE:
  248.         case LOG_ACTION_MARK_SLOTTED_PAGE:
  249.  
  250.             /*
  251.              *    mark the bit
  252.              */
  253.             bm_SetBit((UFOUR *) groupLink->bufFrame, BIT_IN_PAGE(pid->page));
  254.             break;
  255.  
  256.         default:
  257.  
  258.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  259.             break;
  260.     }
  261.  
  262.     /*
  263.      *  mark the page dependency
  264.      */
  265.     DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  266.  
  267.     /*
  268.      *    signal the semaphore
  269.      */
  270.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  271.  
  272.     /*
  273.      *    unfix the page
  274.      */
  275.     bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
  276. }
  277.